package net.lucamasini.fantacalcio.gwt.client.view;

import static net.lucamasini.fantacalcio.gwt.client.Fantacalcio.getEventBus;
import net.lucamasini.fantacalcio.gwt.client.event.HomeEvent;
import net.lucamasini.fantacalcio.server.model.Classifica;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.view.client.HasData;

public class ClassificaPanel extends Composite implements ClassificaView {
    interface Binder extends UiBinder<Widget, ClassificaPanel> {
    }

    private static final Binder BINDER = GWT.create(Binder.class);

    public ClassificaPanel() {
        initWidget(BINDER.createAndBindUi(this));
        
        classificaCellTable.addColumn(new TextColumn<Classifica>() {
			@Override
			public String getValue(Classifica classifica) {
				return classifica.getSquadra();
			}
		}, "PARTITA");

        classificaCellTable.addColumn(new TextColumn<Classifica>() {
			@Override
			public String getValue(Classifica classifica) {
				return Integer.toString(classifica.getPunti());
			}
		}, "PUNTI");
        classificaCellTable.addColumn(new TextColumn<Classifica>() {
			@Override
			public String getValue(Classifica classifica) {
				return Integer.toString(classifica.getRisultatoPieno());
			}
		}, "RIS.<br>PIENO");
        classificaCellTable.addColumn(new TextColumn<Classifica>() {
			@Override
			public String getValue(Classifica classifica) {
				return Integer.toString(classifica.getRisultatoParziale());
			}
		}, "RIS.<br>PARZ.");
    }

    @UiField Label descrizioneGiornata; 
    @UiField Label dataGiornata; 
    @UiField CellTable<Classifica> classificaCellTable;
    @UiField Hyperlink home;
    
    @UiHandler("home")
    void homeClicked(ClickEvent event) {
    	getEventBus().fireEvent(new HomeEvent());
    }
    
	@Override
	public HasData<Classifica> classifica() {
		return classificaCellTable;
	}

    @Override
    public Widget asWidget() {
        return this;
    }

    @Override
    public void setName(String name) {
        throw new UnsupportedOperationException("setName not support yet in "+this.getClass().getName());
    }

    @Override
    public String getName() {
        return "Crea Intervento Panel";
    }


	@Override
	public HasText descrizioneGiornata() {
		return descrizioneGiornata;
	}


	@Override
	public HasText dataGiornata() {
		return dataGiornata;
	}


}
